package net.qiqb.core.domain.event;

import lombok.extern.slf4j.Slf4j;
import net.qiqb.core.trace.TraceId;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * 领域事件上下文
 */
@Slf4j
public class DomainEventContext {

    private final List<DomainEvent> events = new ArrayList<>();

    private TraceId traceId;

    /**
     * 添加领域事件
     */
    public void add(Object... event) {
        if (event == null) {
            return;
        }
        final List<DomainEvent> domainEvents = Arrays.stream(event).map(e -> new DomainEvent("ces", "", e)).toList();
        this.events.addAll(domainEvents);
    }

    /**
     * 移除领域事件
     *
     * @param event
     */
    public void remove(Object... event) {
        if (event == null) {
            return;
        }
        this.events.removeAll(Arrays.asList(event));
    }

    /**
     * 获取事件
     *
     * @return
     */
    public List<DomainEvent> getEvents() {
        return this.events;
    }
}
